#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parse_code.h"
#include "map.h"
#include "symbol.h"
#include "base_func.h" 

#define STR_EQ(s1,s2)	(strcmp(s1,s2)==0)

int findConstant(char *str){
    int length=strlen(str);
    char *c = calloc(length, sizeof(char));

    for(int i=0; i<use_constant; i++){
        if(STR_EQ(str, constant[i]) ) return i;
    }
    constant[use_constant++] = strdup(str);
    return (use_constant-1);
}

int findVariableNode(char *str){
    int length=strlen(str);
    char *c = calloc(length, sizeof(char));

    for(int i=0; i<use_variable_node; i++){
        if(STR_EQ(str, variable_node[i]) ) return i;
    }

    // printf("use_variable_node: %hd\n", use_variable_node);
    // printf("name: %s\n", str);
    variable_node[use_variable_node++] = strdup(str);
    return (use_variable_node-1);
}

Map * SetSystemFunction(){
    Map * sys_func = CreateMap();
    //static Value func = {"printf", DATA_TYPE_SYSTEM_FUNC, { P_output }};
    Value *func = GetValueMemory();

    func->name="printf";
    func->type=DATA_TYPE_SYSTEM_FUNC;
    func->entity->system_func=P_output;
    SetValue(sys_func, func, func->name);

    return sys_func;
}